home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / CPP / ACGIFREE.ZIP / INCLUDE / A_MATRIX.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  6.0 KB  |  155 lines

  1. //a_Matrix based objects
  2.  
  3. #ifndef __RTTI__
  4. #error Must have RTTI enabled in order to use matrix derived classes
  5. #endif
  6.  
  7. //////////////////////////////////////////////////////////////////////
  8. // AMatrixItem; based on ADataItem and AArray
  9. //  a simulated 2D array with emphasis on easy resizing and blitting
  10. //////////////////////////////////////////////////////////////////////
  11. class AMatrixItem : RTTI_VIRTUAL public ADataItem, RTTI_VIRTUAL public AArray
  12. {
  13.   public:
  14.     //a_Declares debug/dump related functions
  15.     #ifdef _DEBUG_DUMP_
  16.       void dump(void);     //a_Debugging dump, when _DEBUG_DUMP_ is set
  17.     #endif
  18. };
  19.  
  20. //////////////////////////////////////////////////////////////////////
  21. // AMatrix base class; based on AList (internally used) and ABaseElement for doOut
  22. //////////////////////////////////////////////////////////////////////
  23. class AMatrix : RTTI_VIRTUAL protected AList, RTTI_VIRTUAL public ABaseElement
  24. {
  25.   public:
  26.     AMatrix()
  27.     {
  28.       m_iX = m_iY = 0x0;
  29.     }
  30.     ~AMatrix() {};
  31.     
  32.     //a_Declares debug/dump related functions
  33.     #ifdef _DEBUG_DUMP_
  34.       void dump(void);     //a_Debugging dump, when _DEBUG_DUMP_ is set
  35.     #endif
  36.  
  37.     //ABaseElement overrides
  38.     virtual void doOut(AStreamOutput *pasOut) const;                          //a_Standard output
  39.  
  40.     //a_Access operator
  41.     AMatrixItem &operator[] (int iPY) { return _mGetAt(iPY); }        //a_Access the row
  42.     int mGetAt(int iPX, int iPY) const;
  43.  
  44.     //a_Redimension the array
  45.     int mSetSize(int iSX, int iSY)
  46.     {
  47.       assert(iSX > 0 && iSY > 0 && iSX < INT_MAX && iSY < INT_MAX);
  48.       if (iSX > 0 && iSY > 0)
  49.       {  
  50.         return _mResize(iSX, iSY);
  51.       }
  52.       else
  53.         assert(0x0);
  54.  
  55.       return 0x0;   //a_Failed!
  56.     }
  57.  
  58.     //a_Blit with an AArray type
  59.     void mBlit(const AArray &aSource, int iPX = 0x0, int iPY = 0x0, int iSX = -0x1, int iSY = -0x1, int iMode = BLIT_COPY);
  60.     void mBlit(const AMatrix &mSource, int iPX = 0x0, int iPY = 0x0, int iSX = -0x1, int iSY = -0x1, int iMode = BLIT_COPY);
  61.  
  62.     //a_Sets the matrix to the given state in a given mode at Pos and Size, default is a clear all
  63.     void mSetPlane(int iState = 0x0, int iMode = BLIT_COPY, int iPX = 0x0, int iPY = 0x0, int iSX = -0x1, int iSY = -0x1);
  64.     
  65.     int mGetHeight(void) const { return m_iY; }
  66.     int mGetWidth(void) const  { return m_iX; }
  67.     UINT mGetSize(void) const  { return UINT(m_iX) * UINT(m_iY); }
  68.  
  69.     //a_Assigning an array out of a linear stream BYTE* (this changes the dimensions)
  70.     void mSetFrom(BYTE *pbSource, int iArraySize, int iSX, int iSY);   //a_Size is in BYTEs!
  71.  
  72.   protected:
  73.     virtual int _mResize(int iSX, int iSY);                     //a_Allocation and resizing
  74.     virtual int _mMapSizetoBYTEs(int iSize) { return iSize; }   //a_1:1 in a BYTE matrix
  75.     virtual int _mGetUnitsInBYTE(void) { return 0x1; }          //a_A BYTE for BYTE... :) (trivial, but useful in case of further expansion of hierarchy)
  76.  
  77.     //a_Verify that the rectangle is within bounds
  78.     void _mFixDimensions(int &iPX, int &iPY, int &iSX, int &iSY);
  79.  
  80.     AMatrixItem &_mGetAt(int iPY)
  81.     {
  82.       assert(m_padiHead);
  83.       AMatrixItem *pmiY = CAST(AMatrixItem *, lGetAt(iPY));
  84.       if (!pmiY) pmiY = CAST(AMatrixItem *, lGetLast());
  85.       assert(pmiY);
  86.       return *pmiY;
  87.     }
  88.  
  89.     virtual void _mSetAt(int iPX, int iPY, int iState, int iMode = BLIT_COPY);
  90.  
  91.     int m_iX, m_iY;                              //a_X is the width, and Y is the height
  92. };
  93.  
  94. //////////////////////////////////////////////////////////////////////
  95. // ABitMatrixItem; based on ADataItem and ABitArray
  96. //////////////////////////////////////////////////////////////////////
  97. class ABitMatrixItem : RTTI_VIRTUAL public ADataItem, RTTI_VIRTUAL public ABitArray
  98. {
  99.   public:
  100.     //a_Declares debug/dump related functions
  101.     #ifdef _DEBUG_DUMP_
  102.       void dump(void);     //a_Debugging dump, when _DEBUG_DUMP_ is set
  103.     #endif
  104. };
  105.  
  106. //////////////////////////////////////////////////////////////////////
  107. // ABitMatrix container of ABitMatrixItem 
  108. //////////////////////////////////////////////////////////////////////
  109. class ABitMatrix : public AMatrix
  110. {
  111.   public:
  112.     ABitMatrix() {};
  113.     ~ABitMatrix() {};
  114.  
  115.     //a_Declares debug/dump related functions
  116.     #ifdef _DEBUG_DUMP_
  117.       void dump(void);     //a_Debugging dump, when _DEBUG_DUMP_ is set
  118.     #endif
  119.  
  120.     //a_Access overrides
  121.     ABitMatrixItem &operator[] (int iPY) { return _mGetAt(iPY); }        //a_Access the row
  122.  
  123.     //ABaseElement overrides
  124.     virtual void doOut(AStreamOutput *pasOut) const { _doBitMatrix(pasOut); }        //a_Standard output
  125.     void bmDoXBitmap(AStreamOutput *pasOut) const   { _doBitMatrix(pasOut, 0x1); }   //a_image/x-xbitmap
  126.  
  127.     //a_Incestuous class dilemma: AMatrixItem and ABitMatrixItem
  128.     //a_Given Z is a child of Y. M is a child of X and Y; N is a child of X and Z
  129.     //a_Will both M and N have correct access from X and Y? Not unless you have RTTI
  130.     //a_This is why I have mSetPlane defined here and not using the one in AMatrix
  131.     void mSetPlane(int iState = 0x0, int iMode = BLIT_COPY, int iPX = 0x0, int iPY = 0x0, int iSX = -0x1, int iSY = -0x1);
  132.  
  133.   protected:
  134.     //a_Output function
  135.     void _doBitMatrix(AStreamOutput *pasOut, int iMirror = 0x0) const;
  136.  
  137.     //a_Getting of the items
  138.     ABitMatrixItem &_mGetAt(int iPY)
  139.     {
  140.       assert(m_padiHead);
  141.       ABitMatrixItem *pbmiY = CAST(ABitMatrixItem *, lGetAt(iPY));
  142.       if (!pbmiY) pbmiY = CAST(ABitMatrixItem *, lGetLast());
  143.       assert(pbmiY);
  144.       return *pbmiY;
  145.     }
  146.  
  147.     //a_Setting functions
  148.     void _mSetAt(int iPX, int iPY, int iState, int iMode = BLIT_COPY);
  149.  
  150.     //a_Redimensioning
  151.     virtual int _mResize(int iSX, int iSY);                          //a_Uses m_iX, m_iY to adjust the size
  152.     virtual int _mMapSizetoBYTEs(int iSize) { return iSize / 0x8; }  //a_8:1 in a bit matrix
  153.     virtual int _mGetUnitsInBYTE(void) { return 0x8; }               //a_8 bits in a BYTE  (trivial, but useful in case of further expansion of hierarchy)
  154. };
  155.